<?php

namespace App\Helpers;

use Dingo\Api\Http\Request;

/**
 * Created by PhpStorm.
 * User: hans
 * Date: 16/6/2
 * Time: 下午8:44.
 */
trait ResponseTrait
{
    /**
     * Response with JSON.
     *
     * @param string $jsonString
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function json($jsonString)
    {
        return response()->make($jsonString, 200, ['Content-Type' => 'application/json']);
    }

    /**
     * 从header authorization中取出token.
     *
     * @param Request $request
     *
     * @return mixed
     */
    public function getTokenFromHeader(Request $request)
    {
        $authorization = trim($request->headers->get('authorization'));
        $tokenArray = explode(' ', $authorization);

        //dd($tokenArray);

        return end($tokenArray);
    }
}
